package com.example.util;

import org.springframework.stereotype.Component;

/**
 * @Description //TODO
 * @Date 2022/10/15 18:41
 * @Author lonng
 **/
@Component
public class GetCodeUtil {

    public String getJava(String requestBody,Integer memoryLimit,Integer timeLimit){
        System.out.println("==============");
        String dataJava = "{\n" +
                "    \"cmd\": [\n" +
                "        {\n" +
                "            \"args\": [\n" +
                "                \"/usr/bin/javac\",\n" +
                "                \"Main.java\"\n" +
                "            ],\n" +
                "            \"env\": [\n" +
                "                \"PATH=/usr/bin:/bin\"\n" +
                "            ],\n" +
                "            \"files\": [\n" +
                "                {\n" +
                "                    \"content\": \"\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"name\": \"stdout\",\n" +
                "                    \"max\": 10240\n" +
                "                },\n" +
                "                {\n" +
                "                    \"name\": \"stderr\",\n" +
                "                    \"max\": 10240\n" +
                "                }\n" +
                "            ],\n" +
                "            \"cpuLimit\": " + 20000000000L + ",\n" +
                "            \"memoryLimit\": " + memoryLimit * 2000 + ",\n" +
                "            \"procLimit\": 50,\n" +
                "            \"copyIn\": {\n" +
                "                \"Main.java\": {\n" +
                "                    \"content\": \"" + requestBody + "\"\n" +
                "                }\n" +
                "            },\n" +
                "            \"copyOut\": [\n" +
                "                \"stdout\",\n" +
                "                \"stderr\"\n" +
                "            ],\n" +
                "            \"copyOutCached\": [\n" +
                "                \"Main.java\"\n" +
                "            ],\n" +
                "            \"copyOutDir\": \"1\"\n" +
                "        }\n" +
                "    ]\n" +
                "}";
        return dataJava;
    }
    public String getCcc(String requestBody,Integer memoryLimit,Integer timeLimit){
        System.out.println("=========");
        requestBody = requestBody.replace("<iostream>", "<iostream>\\n").replace(";", ";\\n");
        String dataCcc = "{\n" +
                "          \"cmd\": [\n" +
                "              {\n" +
                "                  \"args\": [\n" +
                "                      \"/usr/bin/g++\", \n" +
                "                      \"Main.cc\", \n" +
                "                      \"-o\", \n" +
                "                      \"Main\"\n" +
                "                  ], \n" +
                "                  \"env\": [\n" +
                "                      \"PATH=/usr/bin:/bin\"\n" +
                "                  ], \n" +
                "                  \"files\": [\n" +
                "                      {\n" +
                "                          \"content\": \"\"\n" +
                "                      }, \n" +
                "                      {\n" +
                "                          \"name\": \"stdout\", \n" +
                "                          \"max\": 10240\n" +
                "                      }, \n" +
                "                      {\n" +
                "                          \"name\": \"stderr\", \n" +
                "                          \"max\": 10240\n" +
                "                      }\n" +
                "                  ], \n" +
                "            \"cpuLimit\": " + 10000000000L + ",\n" +
                "            \"memoryLimit\": " + memoryLimit * 1000 + ",\n" +
                "                  \"procLimit\": 50, \n" +
                "                  \"copyIn\": {\n" +
                "                      \"Main.cc\": {\n" +
                "                    \"content\": \"" + requestBody + "\"\n" +
                "                      }\n" +
                "                  }, \n" +
                "                  \"copyOut\": [\n" +
                "                      \"stdout\", \n" +
                "                      \"stderr\"\n" +
                "                  ], \n" +
                "                  \"copyOutCached\": [\n" +
                "                      \"Main.cc\", \n" +
                "                      \"Main\"\n" +
                "                  ], \n" +
                "                  \"copyOutDir\": \"1\"\n" +
                "              }\n" +
                "          ]\n" +
                "        }\n" +
                "      }";
        return dataCcc;
    }
    public String getC(String requestBody,Integer memoryLimit,Integer timeLimit){
        System.out.println("=========");
        requestBody = requestBody.replace("<iostream>", "<iostream>\\n").replace(";", ";\\n");
        String dataC = "{\n" +
                "        \"cmd\": [\n" +
                "              {\n" +
                "                  \"args\": [\n" +
                "                      \"/usr/bin/gcc\", \n" +
                "                      \"Main.c\", \n" +
                "                      \"-o\", \n" +
                "                      \"Main\"\n" +
                "                  ], \n" +
                "                  \"env\": [\n" +
                "                      \"PATH=/usr/bin:/bin\"\n" +
                "                  ], \n" +
                "                  \"files\": [\n" +
                "                      {\n" +
                "                          \"content\": \"\"\n" +
                "                      }, \n" +
                "                      {\n" +
                "                          \"name\": \"stdout\", \n" +
                "                          \"max\": 10240\n" +
                "                      }, \n" +
                "                      {\n" +
                "                          \"name\": \"stderr\", \n" +
                "                          \"max\": 10240\n" +
                "                      }\n" +
                "                  ], \n" +
                "            \"cpuLimit\": " + timeLimit * 1000 + ",\n" +
                "            \"memoryLimit\": " + memoryLimit * 1000 + ",\n" +
                "                  \"procLimit\": 50, \n" +
                "                  \"copyIn\": {\n" +
                "                      \"Main.c\": {\n" +
                "                    \"content\": \"" + requestBody + "\"\n" +
                "                      }\n" +
                "                  }, \n" +
                "                  \"copyOut\": [\n" +
                "                      \"stdout\", \n" +
                "                      \"stderr\"\n" +
                "                  ], \n" +
                "                  \"copyOutCached\": [\n" +
                "                      \"Main.c\", \n" +
                "                      \"Main\"\n" +
                "                  ], \n" +
                "                  \"copyOutDir\": \"1\"\n" +
                "              }\n" +
                "          ]\n" +
                "        }\n" +
                "      }";
        return dataC;
    }
    public String getPython(String requestBody,Integer memoryLimit,Integer timeLimit){
        String dataPython = "{\n" +
                "          \"cmd\": [\n" +
                "              {\n" +
                "                  \"args\": [\n" +
                "                      \"/usr/bin/python3 -m py_compile\", \n" +
                "                      \"Main.py\", \n" +
                "                  ], \n" +
                "                  \"env\": [\n" +
                "                      \"PATH=/usr/bin:/bin\"\n" +
                "                  ], \n" +
                "                  \"files\": [\n" +
                "                      {\n" +
                "                          \"content\": \"\"\n" +
                "                      }, \n" +
                "                      {\n" +
                "                          \"name\": \"stdout\", \n" +
                "                          \"max\": 10240\n" +
                "                      }, \n" +
                "                      {\n" +
                "                          \"name\": \"stderr\", \n" +
                "                          \"max\": 10240\n" +
                "                      }\n" +
                "                  ], \n" +
                "            \"cpuLimit\": " + timeLimit * 1000 + ",\n" +
                "            \"memoryLimit\": " + memoryLimit + ",\n" +
                "                  \"procLimit\": 50, \n" +
                "                  \"copyIn\": {\n" +
                "                      \"Main.py\": {\n" +
                "                    \"content\": \"" + requestBody + "\"\n" +
                "                      }\n" +
                "                  }, \n" +
                "                  \"copyOut\": [\n" +
                "                      \"stdout\", \n" +
                "                      \"stderr\"\n" +
                "                  ], \n" +
                "                  \"copyOutCached\": [\n" +
                "                      \"Main.py\"\n" +
                "                  ], \n" +
                "                  \"copyOutDir\": \"1\"\n" +
                "              }\n" +
                "          ]\n" +
                "        }\n" +
                "      }";
        return dataPython;
    }

    public String getJavaCode(String fileId,
                          Integer timeLimit, Integer memoryLimit,
                          Integer stackLimit,String files){
            String code = "{\n" +
                    "    \"cmd\": [{\n" +
                    "        \"args\": [\"/usr/bin/javac\",\n\"Main\"],\n" +
                    "        \"env\": [\"PATH=/usr/bin:/bin\",\"LANG=en_US.UTF-8\",\"LC_ALL=en_US.UTF-8\",\"LANGUAGE=en_US:en\"],\n" +
                    "        \"files\": [{\n" +
                    "            \"src\": \"" + files + "\"\n" +
                    "        }, {\n" +
                    "            \"name\": \"stdout\",\n" +
                    "            \"max\": 10240\n" +
                    "        }, {\n" +
                    "            \"name\": \"stderr\",\n" +
                    "            \"max\": 10240\n" +
                    "        }],\n" +
                    "        \"cpuLimit\": " + 20000000000L + ",\n" +
                    "        \"realCpuLimit\":30000000000,\n" +
                    "        \"stackLimit\":" + stackLimit + ",\n" +
                    "        \"memoryLimit\": " + memoryLimit + ",\n" +
                    "        \"procLimit\": 50,\n" +
                    "        \"copyIn\": {\n" +
                    "            \"Main\":{\"fileId\":\"" + fileId + "\"}\n" +
                    "        },\n" +
                    "        \"copyOut\": [\"stdout\", \"stderr\"]\n" +
                    "    }]\n" +
                    "}";
            return code;

    }
    public String getCccCode(String fileId,
                              Integer timeLimit, Integer memoryLimit,
                              Integer stackLimit,String files){
        String code = "{\n" +
                "    \"cmd\": [{\n" +
                "        \"args\": [\"Main\"],\n" +
                "        \"env\": [\"PATH=/usr/bin:/bin\",\"LANG=en_US.UTF-8\",\"LC_ALL=en_US.UTF-8\",\"LANGUAGE=en_US:en\"],\n" +
                "        \"files\": [{\n" +
                "            \"src\": \"" + files + "\"\n" +
                "        }, {\n" +
                "            \"name\": \"stdout\",\n" +
                "            \"max\": 10240\n" +
                "        }, {\n" +
                "            \"name\": \"stderr\",\n" +
                "            \"max\": 10240\n" +
                "        }],\n" +
                "        \"cpuLimit\": " + 20000000000L + ",\n" +
                "        \"realCpuLimit\":30000000000,\n" +
                "        \"stackLimit\":" + stackLimit + ",\n" +
                "        \"memoryLimit\": " + memoryLimit*10 + ",\n" +
                "        \"procLimit\": 50,\n" +
                "        \"copyIn\": {\n" +
                "            \"Main\":{\"fileId\":\"" + fileId + "\"}\n" +
                "        },\n" +
                "        \"copyOut\": [\"stdout\", \"stderr\"]\n" +
                "    }]\n" +
                "}";
        return code;

    }
}
